﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo._7C
{
    public partial class KullanimYeri : XForm
    {
        int CikisPartisiId = 0;
        public KullanimYeri(int _CikisPartisiId)
        {
            InitializeComponent();
            CikisPartisiId = _CikisPartisiId;
            this.Text += " - " + CikisPartisiId.ToString();
        }

        private void KullanimYeri_Load(object sender, EventArgs e)
        {
            gridView1.Init("Get7CKullanimYeri", CikisPartisiId);
            gridView1.AddDetailGrid(gridView2, "ProductId", 1);
            gridView1.AddDetailGrid(gridView3, "ProductId", 2);
            gridView1.MakeColumnInvisible("Name");

            gridView1.AddColumn("QtyAx", typeof(decimal), "SUM(Child({FK}).QtyAx)", 0);
            gridView1.AddColumn("QtyGx", typeof(decimal), "SUM(Child({FK}).QtyGx)", 0);
            gridView1.AddColumn("TotalQty", typeof(decimal), "QtyAx+QtyGx");
            gridView1.AddColumn("Ayrilan", typeof(decimal), "SUM(Child({FK}).Qty)", 1);
            gridView1.AddColumn("Fark", typeof(decimal), "Ayrilan-TotalQty");
            gridView1.FormatAsNumber(1, "QtyAx", "QtyGx", "TotalQty", "Ayrilan", "Fark");
            gridView2.FormatAsNumber(1, "QtyAx", "QtyGx");
            gridView3.FormatAsNumber(1, "Qty", "En");
            gridView1.AddSummary("QtyAx", "QtyGx", "TotalQty", "Ayrilan", "Fark");
            gridView2.AddSummary("QtyAx", "QtyGx");
            gridView3.AddSummary("Qty");
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            gridView3.BestFitColumns();

            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
            splitContainerControl2.AutoSize();
        }


        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle > -1)
            {
                gridView2.BestFitColumns();
                gridView3.BestFitColumns();
                txtInfo.Caption = gridView1.GetFocusedRowCellDisplayText("ProductId");
            }
            else
                txtInfo.Caption = string.Empty;
        }

    }
}